package com.go.struts2.action.ajax;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

import org.apache.struts2.json.annotations.JSON;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class AjaxAction extends ActionSupport {
	private User user;
	private InputStream inputStream;
	private String schoolId;
	private String code;

	public InputStream getInputStream() {
		return inputStream;
	}

	public String execute() throws Exception {
		return SUCCESS;
	}

	public String checkUser() throws Exception {
		System.out.println("name => " + user.getName());
		if ("admin".equals(user.getName())) {
			inputStream = new ByteArrayInputStream("用户名已经存在".getBytes("utf-8"));
		} else {
			inputStream = new ByteArrayInputStream("用户名不存在".getBytes("utf-8"));
		}
		return SUCCESS;
	}

	public String queryAllClass() {
		String id = "";
		String name = "";
		// int sId = Integer.parseInt(schoolId);// 把从前台传来的参数转换成int类型的
		for (int i = 0; i < 10; i++) {
			id += i + "_";
			name += "clsname" + i + "_";
		}
		code = id + "|" + name + "|class";
		return SUCCESS;
	}

	public String getSchoolId() {
		return schoolId;
	}

	public void setSchoolId(String schoolId) {
		this.schoolId = schoolId;
	}

	@JSON(name = "code")
	public String getCode() {
		return code;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
}
